<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>宠物医院信息管理系统</title>
<link href="css/bootstrap.min.css" rel='stylesheet' type='text/css' />
<link href="css/style.css" rel='stylesheet' type='text/css' />
</head>
<body id="loginbody">

<div id="loginIn">
	<table>
		<tr><td><h2>管理员登录</h2></td></tr>
		<tr>
			<td>
				<input class="form-control" id="username" type="text" placeholder="用户名">
			</td>
		</tr>
		<tr>
			<td>
				<input class="form-control" id="password" type ="password" placeholder="密码">
			</td>
		</tr>
		<tr>
			<td>&nbsp;</td>
		</tr>
		<tr>
			<td>
				<select class="form-control" name="role" id="role">
					<option value="0">管理员</option>
					<option value="1">工作人员</option>
				</select>
			</td>
		</tr>
		<tr>
			<td>
				<button id="login" class="btn btn-lg btn-primary btn-block">登录</button>
			</td>
		</tr>
	</table>

</div>
<script type="text/javascript" src="js/jquery-1.11.3.min.js"></script>
<script type="text/javascript" src="js/public_fuc.js"></script>
<script type="text/javascript">
	$(function(){
		$("#login").click(function(){
			var username = $("#username").val();
			var password = $("#password").val();
			var obj = {};
			obj.password = password;
			obj.username = username;
			var role = $('#role').val();
			var url = 'api/admin/list';
			if(role=='1'){
				url = "api/staff/list";
				
			}
			$.get("api/login",{username:username,password:password},function (data) {
				if (data.code==404 || data.code==505){
					alert(data.msg);
				}else{
					alert(data.msg);
					window.location.href="management/index.jsp";
				}
			})


			//
			// $.get(url,obj,function(data){
			// 	if(data.code=='0'){
			// 		console.log(data);
			// 		if(role=='1'){
			// 			var arr = data.data;
			// 			setCookie('staff', 'role'+arr[0].role.id)
			// 		}else{
			// 			deleteCookie('staff');
			// 		}
			// 		window.location.href="management/index.jsp";
			// 	}else{
			// 		alert("用户名或密码错误！");
			// 	}
			//
			// });
		});
	})

</script>
</body>
</html>